<?
	layout("/inc/win_layout.html",{title:sysTitle}){
?>
	<link rel="stylesheet" href="static/uploadify/uploadify.css" type="text/css"></link>
	<script type="text/javascript" src="static/uploadify/jquery.uploadify.min.js"></script>
    <script type="text/javascript" src="static/utf8-jsp/ueditor.config.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/ueditor.all.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/lang/zh-cn/zh-cn.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/third-party/video-js/video.js"></script>
	<script type="text/javascript" src="static/My97DatePicker/WdatePicker.js"></script>
	<div class="panel panel">
	<div class="panel-body pan" style="height: 540px; overflow: auto;">
		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">中文名称
					<span class='require' >*</span>
				</label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="nameNewsZh" type="text" onchange="chinese_spell(this.value)" class="form-control" value="" />
					</div>
				</div>
			</div>
			<div  class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">英文名称
					<span class='require' >*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="nameNewsEn" type="text" class="form-control"
							value="" />
					</div>
				</div>
			</div>
		</div>
		<div class="row" style="margin-bottom: 10px;">
			<div id = "passwordParent" class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">排序
					<span class='require' id="yonghu">*</span> </label>
				<div class="col-md-9">
					<div class="input-icon">
						<input id="sort" type="text" class="form-control"
							value="" />
					</div>
				</div>
			</div>
			<div class="col-lg-6 clearfix"
				style="width: 395px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">是否显示更多<span
						class='require'>*</span> 
				</label>
				<div class="col-md-9 clearfix">
					<div class="input-icon">
						<select id="showMore" class="form-control">
							<option value="0">显示</option>
							<option value="1">不显示</option>
						</select>
					</div>
				</div>
			</div>
		</div>
		
		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6 clearfix"
				style="width: 395px; float:left; margin-right:-20px; display:inline;">
				<input type="hidden" id ="dataTypeId">
				<label for="inputUsername" class="col-md-3 control-label">数据类型<span
						class='require'>*</span> 
				</label>
				<div class="col-md-9 clearfix">
					<div class="input-icon">
						<select id="dataType" class="form-control" onchange = "dataTypeChange()">
							<option value="0">固定数据</option>
							<option value="1">动态数据</option>
						</select>
					</div>
				</div>
			</div>
			<div class="col-lg-6 clearfix"
				style="width: 395px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">是否推荐数据<span
						class='require'>*</span> 
				</label>
				<div class="col-md-9 clearfix">
					<div class="input-icon">
						<select id="recommend" class="form-control" >
							<option value="0">否</option>
							<option value="1">是</option>
						</select>
					</div>
				</div>
			</div>
		</div>
		
		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6 clearfix"
				style="width: 395px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">块类型<span
						class='require'>*</span> 
				</label>
				<div class="col-md-9 clearfix">
					<div class="input-icon">
						<select id="moduleType" class="form-control" onchange="moduleTypeChange()">
							<option value="0">关联新闻栏目</option>
							<option value="1">关联资源库</option>
							<option value="2">html内容</option>
						</select>
					</div>
				</div>
			</div>
			
			<div class="col-lg-6 clearfix"
				style="width: 395px; float:left; margin-right:-20px; display:inline;">
				<!-- <input type="hidden" id ="dataTypeId"> -->
				<label for="inputUsername" class="col-md-3 control-label">内容类型<span
						class='require'>*</span> 
				</label>
				<div class="col-md-9 clearfix">
					<div class="input-icon">
						<select id="contentType" class="form-control" onchange = "clearText()">
							<option value="0">文字模式</option>
							<option value="1">图文模式</option>
						</select>
					</div>
				</div>
			</div>
		</div>
		
		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6 clearfix"
				style="width: 395px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">布局<span
						class='require'>*</span> 
				</label>
				<div class="col-md-9 clearfix">
					<div class="input-icon">
						<select id="layoutStyle" class="form-control">
							<option value="2">2</option>
							<option value="4">4</option>
							<option value="6">6</option>
							<option value="8">8</option>
							<option value="12">12</option>
						</select>
					</div>
				</div>
			</div>
			
			<div id = "passwordParent" class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">样式
					</label>
				<div class="col-md-9">
					<div class="input-icon">
						<select id="styleCss" class="form-control">
							<option value="1">样式1</option>
							<option value="2">样式2</option>
							<option value="3">样式3</option>
						</select>
					</div>
				</div>
			</div>
			
			<!-- <div class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">父节点 
					<span class='require' >*</span> </label>
				<div class="col-md-9">
					<div class="input-group input-group-sm mbs">
						<input id="mineParentName" type="text"  value="根节点" class="form-control" disabled="true" /> 
						<span class="input-group-btn">
							<button onclick="mineZTree()" id="classButton" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择...</button>
						</span> 
						<input id="mineParentId" type="hidden" value="0" class="form-control" />
					</div>
				</div>
			</div> -->
		</div>
		
		<div class="row" style="margin-bottom: 10px;display:none;" id="dataTypefi">
			<div class="col-lg-12" id = "datasetTextId"
				style="width:98%; float:left; margin-right:-20px;display:none;">
				<label for="inputUsername" class="col-md-3 control-label">数据集
					</label>
				<div class="col-md-12">
					<div class="input-group input-group-sm mbs">
						<input id="datasetText" type="text"  value="" class="form-control" disabled="true" /> 
						<span class="input-group-btn">
							<button onclick="leaveType()" id="classButton" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择</button>
							<button onclick="" id="clearButton" type="button" data-toggle="dropdown" class="btn btn-primary dropdown-toggle">清空</button>
						</span> 
						<input id="datasetId" type="hidden" value="0" class="form-control" />
					</div>
				</div>
			</div>
			
			<div class="col-lg-12" id="htmlTextId"
				style="width:98%; float:left; margin-right:-20px;display:none;">
				<label for="inputUsername" class="col-md-3 control-label">html内容
					</label>
				<div class="col-md-12">
					<div class="input-group input-group-sm mbs">
						<input id="htmlText" type="text"  value="" class="form-control" disabled="true" /> 
						<span class="input-group-btn">
							<button onclick="leaveType()" id="classButton" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">编写...</button>
						</span> 
					</div>
				</div>
			</div>
		</div>
		
		<div class="row" style="margin-bottom: 10px;display:none;" id="dataTypedy">
			<div class="col-lg-12" id = "categoryHide"
				style="width:98%; float:left; margin-right:-20px;display:none;">
				<label for="inputUsername" class="col-md-3 control-label">新闻栏目
					</label>
				<div class="col-md-12">
					<div class="input-group input-group-sm mbs">
						<input id="categoryText" type="text"  value="" class="form-control" disabled="true" /> 
						<span class="input-group-btn">
							<button onclick="openColumn()" id="classButton" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择...</button>
						</span> 
						<input id="datasetId" type="hidden" value="0" class="form-control" />
					</div>
				</div>
			</div>
			
			<div class="col-lg-12" id="classesHide"
				style="width:98%; float:left; margin-right:-20px;display:none;">
				<label for="inputUsername" class="col-md-3 control-label">知识库<span
						class='require'>*</span> 
				</label>
				<div class="col-md-9 clearfix">
					<div class="input-icon">
						<select id="relevanceClasses" class="form-control">
							
						</select>
					</div>
				</div>
			</div>
		</div>
		<div class="row" style="margin-bottom: 10px;">
			<div  class="col-lg-6"
				style="width: 400px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">权限用户
					<!-- <span class='require' id="yonghu">*</span> --> </label>
				<div class="col-md-9">
					<div class="input-group input-group-sm mbs">
						<input id="permissionsZh" type="text"  value="*" class="form-control" disabled="true" /> 
						<span class="input-group-btn">
							<button onclick="findMember()" id="classButton" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择...</button>
						</span> 
						<input id="permissionsId" type="hidden" value="0" class="form-control" />
					</div>
				</div>
			</div>
			<div class="col-lg-6 clearfix"
				style="width: 395px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">状态<span
						class='require'>*</span> 
				</label>
				<div class="col-md-9 clearfix">
					<div class="input-icon">
						<select id="status" class="form-control">
							<option value="0">启用</option>
							<option value="1">禁用</option>
						</select>
					</div>
				</div>
			</div>
		</div>
		
		<div class="row" style="margin-bottom: 10px;">
			<div class="col-lg-6 clearfix"
				style="width: 395px; float:left; margin-right:-20px; display:inline;">
				<label for="inputUsername" class="col-md-3 control-label">页面打开方式<span
						class='require'>*</span> 
				</label>
				<div class="col-md-9 clearfix">
					<div class="input-icon">
						<select id="openWith" class="form-control">
							<option value="0">本页面</option>
							<option value="1">新页面</option>
						</select>
					</div>
				</div>
			</div>
		</div>
		
	 </div>
	</div>
</div>
<?} ?>
<script>
	var index1 = window.parent.getlay();
	var typeId = "";
	var dynamicId = "";
	var contentId = "";
	/* var _editor; */
	var classesIds = "";
	$(function() {
		showClass();
		if (index1 != 0) {
			$.ajax({
				type : "post",
				url : "findCmsNewsModule.do",
				data : {
					"id":index1
				},
				dataType : "json",
				traditional : true,
				success : function(data) {
					if(data.msg == "OK"){
						$("#nameNewsZh").val(data.data.nameZh);
						$("#nameNewsEn").val(data.data.nameEn);
						$('#nameNewsEn').attr("disabled",true);
						$("#sort").val(data.data.sort);
						$("#status").val(data.data.status);
						$("#showMore").val(data.data.showMore);
						$("#layoutStyle").val(data.data.layoutStyle);
						$("#styleCss").val(data.data.cssStyle);
						$("#contentType").val(data.data.contentType);
						$("#dataType").val(data.data.dataType);
						$("#moduleType").val(data.data.moduleType);
						$("#recommend").val(data.data.recommend);
						$("#permissionsId").val(data.tree.permissionsId);
						$("#permissionsZh").val(data.tree.permissionsName);
						$("#openWith").val(data.data.openWith);
						moduleTypeChange();
						dataTypeChange();
						if(data.data.dataType == 0){
							if(data.data.moduleType == 0 || data.data.moduleType == 1){
								$("#datasetText").val(data.data.dataset);
								$("#datasetTextId").show();
								$("#htmlTextId").hide();
							}
							if(data.data.moduleType == 2){
								$("#htmlText").val(data.data.htmlText);
								$("#datasetTextId").hide();
								$("#htmlTextId").show();
							}
						}else{
							if(data.data.moduleType == 0){
								$("#dataTypeId").val(data.tree.CategoryId);
								$("#categoryText").val(data.tree.CategoryName);
							}
							if(data.data.moduleType == 1){
								$("#relevanceClasses").val(data.data.relevanceClassesEn);
							}
							
						}
					}else{
						alert("请求失败");
					}
				},
				error : function(data) {
					
				}
			});
		
		}
		moduleTypeChange();
		dataTypeChange();
		 
	});
	function getModuleType(){
		return typeId;
	}
	function getDynamic(){
		return dynamicId;
	}
	function getContent(){
		return contentId;
	}
	function save() {
		/* var saveText = UE.getEditor('containerText'); */
		//获取html内容
		/* var ueditortext = saveText.getContent(); */
		var regexSort = /^[0-9]*$/;
		if($.trim($("#nameNewsZh").val()).length<1) {
    	        	alert('中文名称不能为空');
    	        	return null;
    	    }
		 if($.trim($("#nameNewsEn").val()).length<1) {
    	        	alert('英文名称不能为空');
    	        	return null;
    	    }
		 if($.trim($("#sort").val()).length<1) {
    	        	alert('排序不能为空！');
    	        	return null;
    	    }
		 if(!regexSort.test($("#sort").val())){
    		alert('排序请输入数字！');
	        return null;
    	}
		$.ajax({
			type : "post",
			url : "addUpdateCmsNewsMoudle.do",
			data : {
				"nameZh":$("#nameNewsZh").val(),
				"nameEn":$("#nameNewsEn").val(),
				"sort":$("#sort").val(),
				"status":$("#status").val(),
				"showMore":$("#showMore").val(),
				"layoutStyle":$("#layoutStyle").val(),
				"styleCss":$("#styleCss").val(),
				"contentType":$("#contentType").val(),
				"dataType":$("#dataType").val(),
				"moduleType":$("#moduleType").val(),
				"recommend":$("#recommend").val(),
				"relevanceClasses":$("#relevanceClasses").val(),
				"permissionsId":$("#permissionsZh").val(),
				"openWith":$("#openWith").val(),
				"datasetId":$("#dataTypeId").val(),
				"datasetText":$("#datasetText").val(),
				"htmlText":$("#htmlText").val(),
				"id":index1,
			},
			dataType : "json",
			traditional : true,
			success : function(data) {
				if(data.msg == "OK"){
					var index = parent.layer.getFrameIndex(window.name);
					window.parent.demo(1);
					parent.layer.msg('提交成功');
					parent.layer.close(index);
				}else{
					alert("请求失败");
				}
			},
			error : function(data) {
				
			}
		});
	}
	
	
	
	function leaveType(){
		typeId = $("#moduleType").val();
		dynamicId = $("#dataType").val();
		contentId = $("#contentType").val();
		/* alert(typeId) */
		parent.layer.open({
			type : 2,
			area : [ '900px', '700px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			//move : false,
			title:"数据集",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["cms-news-module-type.html?winName="+window.name, 'no'],
			yes : function(index,layer) {		
			var iframeWin = parent.window[layer.find('iframe')[0]['name']];
			  	iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	}
	/*权限用户*/
	function findMember(){
		parent.layer.open({
			type : 2,
			area : [ '900px', '700px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			//move : false,
			title:"授权用户列表",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["cms-navbar-user.html?winName="+window.name, 'no'],
			yes : function(index,layer) {		
			var iframeWin = parent.window[layer.find('iframe')[0]['name']];
			  	iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	}
	
	
	
	/*汉字转化拼音*/
	
   function chinese_spell(spell){
	  /* if(objectPropertyid == 0){ */
	  	/* if(cop == 00){ */
	  	var reg = "[A-Z]+";     
        var r = spell.match(reg);
	        if(r == null){
				$.ajax({
					type : "post",
					url : "pinYin.do",
					data : {
						"pinYin" : spell,
					},
					async : false,
					dataType : "json",
					success : function(data) {
						/* if(data[0].length > 20){ */
							$("#nameNewsEn").val(data);
						/* } */
					},
					error : function(data) {
						alert("请求失败");
					}
				});
			}else{
				alert("英文名不可存在大写，请手动输入英文名");
				$("#analysisEnname").val("");
			}
		/* } */
		/* } */
	}
	
	function moduleTypeChange(){
		$("#datasetText").val("");
		$("#htmlText").val("");
		$("#categoryText").val("");
		if($("#dataType").val() == 0){
			if($("#moduleType").val() == 0 || $("#moduleType").val() == 1){
				$("#datasetTextId").show();
				$("#htmlTextId").hide();
			}else if($("#moduleType").val() == 2){
				$("#datasetTextId").hide();
				$("#htmlTextId").show();
			}
		}else{
			if($("#moduleType").val() == 0){
				$("#categoryHide").show();
				$("#classesHide").hide();
			}
			if($("#moduleType").val() == 1){
				/* showClass(); */
				$("#categoryHide").hide();
				$("#classesHide").show();
			}
			
		}
	}
	
	function dataTypeChange(){
		if($("#dataType").val() == 0){
			$("#dataTypefi").show();
			$("#dataTypedy").hide();
		}else{
			$("#dataTypedy").show();
			$("#dataTypefi").hide();
		}
		moduleTypeChange();
	
	}
	/*关联知识库*/
	function showClass(){
		$.ajax({
			type : "post",
			url : "selectClass.do",
			data : {
			},
			dataType : "json",
			success : function(data) {
				if(data.msg == "OK"){
					var content = "";
					$.each(data.data,function(k,v){
						content += '<option value="'+v.nameEn+'">'+v.nameZh+'</option>'
					})
					$("#relevanceClasses").html(content);
				}else{
					alert("请求失败");
				}
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	
	function openColumn(){
		pageId = 1;
		parent.layer.open({
			type : 2,
			area : [ '560px', '600px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			//move : false,
			title : "选择关联新闻栏目",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : [
					"cms-news-category-add-ztree.html?winName="+ window.name, 'no' ],
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	}
	/*清空按钮*/
	$("#clearButton").click(function(){
		$("#datasetText").val("");
	})
	function clearText(){
		$("#datasetText").val("");
		$("#categoryText").val("");
		showClass();
	}
</script>